package com.sgb.member.view_model;


import com.sgb.member.di.repository.MemberRepertory;
import com.sgb.member.ui.activity.MemberBusinessActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.view.countmenu.CountMenuEntity;

import java.util.List;

import retrofit2.Call;

public class MemberBusinessModel extends BaseViewModel {

    private MemberBusinessActivity activity;
    private MemberRepertory repertory;

    public MemberBusinessModel(MemberBusinessActivity activity, MemberRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

    // 会员商机首页图标接口
    public void getOperationIcons() {
        showOrHideDialog(true);
        repertory.getApi().getOperationIcons().enqueue(new ICallBack<BaseEntity<List<CountMenuEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CountMenuEntity>> data) {
                if (data.getData() != null && data.getData().size() > 0) {
                 //   activity.refreshMenus(data.getData());
                } else {
                    showOrHideDialog(false);
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<CountMenuEntity>>> call, Throwable t) {
                super.onFailure(call, t);
                showOrHideDialog(false);
            }

            @Override
            public void onFinally() {

            }
        });
    }
    public void showOrHideDialog(boolean aBoolean) {
        if (aBoolean) {
            if (!DialogHelper.isShowing()) {
                DialogHelper.showProgressDialog(activity, "数据获取中...");
            }
        } else {
            DialogHelper.dismissProgressDialog();
        }
    }
}
